package com.tw.academy.basic.$4_naming.practiceTwo;

public class PigLatin {
    private static final String DELIMITER = " ";
    private static final String WORD_SEPARATOR = " ";
    private static final String SUFFIX = "ay";

    public static String pigIt(String sentence) {
        String[] marks = {".",",","-",":",";","!","?"};
        String[] words = sentence.split(WORD_SEPARATOR);
        char firstLetter;
        boolean flag = true;

        for (int i = 0; i < words.length; i++){
            for (String mark : marks)
                if (words[i].contains(mark))
                    flag = false;

            if (flag){
                firstLetter = words[i].charAt(0);
                words[i] = words[i].substring(1);
                words[i] += firstLetter + SUFFIX;
            }
            flag = true;
        }

        return String.join(DELIMITER, words);
    }
}
